//
//  BHCommonStadiumModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/28.
//

import UIKit

class BHCommonStadiumModel {
    var stadiumId: String = ""
    var name: String = ""
    var cover: String = ""
    var cityName: String = ""
    var regionName: String = "" // 区域
    var distance: String = ""
    
    
    var goodsArray: [BHCommonStadiumGoodsModel] = []
    
    
    func parseDic(_ dic: [String: Any])  {
        self.stadiumId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.name = BHJsonTool.decodeStringFromDic(dic: dic, key: "name")
        self.cover = BHJsonTool.decodeStringFromDic(dic: dic, key: "cover")
        self.cityName = BHJsonTool.decodeStringFromDic(dic: dic, key: "cityName")
        self.regionName = BHJsonTool.decodeStringFromDic(dic: dic, key: "regionName")
        self.distance = BHJsonTool.decodeStringFromDic(dic: dic, key: "distance")

        let goods = BHJsonTool.decodeArrayFromDic(dic: dic, key: "goods")
        if goods.count != 0 {
            for goodDic in goods {
                if goodDic is NSNull{
                    continue
                }else {
                    let model = BHCommonStadiumGoodsModel.init()
                    model.price = BHJsonTool.decodeStringFromDic(dic: (goodDic as! Dictionary<String, Any>), key: "price")
                    model.name = BHJsonTool.decodeStringFromDic(dic: (goodDic as! Dictionary<String, Any>), key: "name")
                    model.typeName = BHJsonTool.decodeStringFromDic(dic: (goodDic as! Dictionary<String, Any>), key: "typeName")
                    self.goodsArray.append(model)
                }
            }
        }
    }
    
    lazy var showArea: String = {
        if self.cityName.isEmpty == true && self.regionName.isEmpty == true {
            return ""
        }else {
            if self.cityName.isEmpty == true {
                return self.regionName
            }
            else if self.regionName.isEmpty == true {
                return self.cityName
            }else {
                return self.cityName+"/"+self.regionName
            }
        }
       
    }()
    
    lazy var showDistance: String = {
        if self.distance.isEmpty == true {
            return ""
        }else {
            return self.distance+"m"
        }
    }()
    
    
    lazy var cellHeight: CGFloat = {
        if self.goodsArray.count >= 2 {
            return 154
        }else if self.goodsArray.count == 1 {
            return 125
        }else {
            return 90
        }
    }()
}

class BHCommonStadiumGoodsModel {
    var price: String = ""
    var name: String = ""
    var typeName: String = "" //商品类型
}
